home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / pascalMode.tcl < prev    next >
Encoding:
Text File  |  1999-05-13  |  2.4 KB  |  80 lines  |  [TEXT/ALFA]

  1. # (auto-install)
  2. alpha::mode Pasc 1.0.2 dummyPascal {*.p} {thinkRefMenu toolboxRefMenu electricSemicolon electricTab electricReturn} {
  3.     set unixMode(pascal) {Pasc}
  4. }
  5.  
  6.  
  7. newPref v leftFillColumn {3} Pasc
  8. newPref v wordBreak {\w+} Pasc
  9. newPref f wordWrap {0} Pasc
  10. # newPref v funcExpr {^[^ \t\(#\r/@].*\(.*\)$} Pasc
  11. # newPref v parseExpr {^[^ \t\(#\r/@].*\((.*)\)$} Pasc
  12. newPref v funcExpr {^procedure.*\(} Pasc
  13. newPref v parseExpr {^procedure[ \t]*(.*)[ \t]*\(} Pasc
  14. newPref v wordBreakPreface {\W} Pasc
  15. newPref f autoMark    0 Pasc
  16.  
  17. set pascCommentRegexp    {/\*(([^*]/)|[^*]|\r)*\*/}
  18. set pascPreRegexp        {^\#[\t ]*[a-z]*}
  19. set pascKeyWords        {
  20.     procedure function integer while with return var const unit type interface
  21.     packed record begin end boolean if else repeat for downto case to of mod 
  22.     goto file do then program or label div until set not in forward and
  23.     implementation unit
  24. }
  25. regModeKeywords -b \{ \} -c red -k blue Pasc $pascKeyWords
  26. unset pascKeyWords
  27.  
  28. hook::register saveHook modified "Pasc"
  29.  
  30. #================================================================================
  31.  
  32. proc dummyPascal {} {}
  33.  
  34. set commentCharacters(Pasc:Paragraph) [list "(*" "*)" " * "]
  35.  
  36.  
  37. proc Pasc::MarkFile {} {
  38.     message "Not yet (someone write me)"
  39. }
  40.  
  41. proc Pasc::indentLine {} {
  42.     # get details of current line
  43.     set beg [lineStart [getPos]]
  44.     set text [getText $beg [nextLineStart $beg]]
  45.     regexp "^\[ \t\]*" $text white
  46.     set len [string length $white]
  47.     set epos [pos::math $beg + $len]
  48.     
  49.     # Find last previous non-comment line and get its leading whitespace
  50.     set pos $beg
  51.     while 1 {
  52.     if {[catch {search -s -f 0 -r 1 -i 0 -m 0 "^\[ \t\]*\[^ \t\r\n\]" [pos::math $pos - 1]} lst]} {
  53.         # search failed at top of file
  54.         set line "#"
  55.         set lwhite 0
  56.         break
  57.     }
  58.     if {![catch {text::inCommentBlock [lindex $lst 0]} res]} {
  59.         set pos [lindex $res 0]
  60.     } else {
  61.         set line [getText [lindex $lst 0] [pos::math [nextLineStart [lindex $lst 0]] - 1]]
  62.         set lwhite [posX [pos::math [lindex $lst 1] - 1]]    
  63.         break
  64.     }
  65.     }
  66.     
  67.     global indentationAmount electricColon
  68.     if {[regexp "begin\[ \t\]*$" $line]} {
  69.     incr lwhite $indentationAmount
  70.     }
  71.     if {[regexp "end;?\[ \t\r\n\]*$" [getText $epos [nextLineStart $epos]]]} {
  72.     incr lwhite [expr -$indentationAmount]
  73.     }
  74.     set lwhite [text::indentOf $lwhite]
  75.     if {$white != $lwhite} {
  76.     replaceText $beg $epos $lwhite
  77.     }
  78.     goto [pos::math $beg + [string length $lwhite]]
  79. }
  80.